const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    //筛选数据
    filterList: [],
  },


  /**
   * 筛选菜单-开关
   */
  showFilter() {
    this.setData({
      filterShow: !this.data.filterShow
    })
  },

  /**
   * 确认筛选条件
   */
  confirmFilter(){
    console.log(this.data.filterList);
    let idStr =  '';
    let list = this.data.filterList;
    for(let key in list){
      for(let inx in list[key]['children']){
        if (list[key]['children'][inx].chooesed){
          idStr += list[key]['children'][inx]['filter_id'] + ',';
        }
      }
    }
    if('' != idStr){
      wx.setStorageSync('filter_id', idStr.substring(0, idStr.length - 1));
    }
    wx.navigateBack()
  },

  /**
   * 选中筛选条件
   */
  chooesFilter(e) {
    let _this = this;
    let parentInx = e.currentTarget.dataset.parentinx;
    let childrenInx = e.currentTarget.dataset.childreninx;
    let data = _this.data.filterList;
    if (parentInx >= 0 && childrenInx >= 0) {
      for (let key in data[parentInx]) {
        for (let inx in data[parentInx]['children']) {
          data[parentInx]['children'][inx].chooesed = childrenInx == inx ? true : false;
        }
      }
      _this.setData({
        filterList: data,
      })
      return;
    }
    _this.proFilterList(data);
  },
  /**
   * 重置筛选数据
   */
  proFilterList(data) {
    for (let key in data) {
      for (let inx in data[key]['children']) {
        data[key]['children'][inx].chooesed = false;
      }
    }
    this.setData({
      filterList: data
    })
    wx.removeStorageSync('filter_id');
  },
  /**
   * 获取筛选数据
   */
  getFilterList() {
    let _this = this;
    app.HttpsRequest('filter/getlist', 'GET').then(ret => {
      _this.proFilterList(ret.data);
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getFilterList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})